<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Article_model extends CI_Model{

  public function __construct(){
      parent::__construct();

  }
  /*查询全部记录,返回结果数组*/
  public function article_list(){
    $data = $this ->db->select('aid,title,time,cid,thumb,content')->get('article')->result_array();
    return $data;
  }

  /*查询全部记录,返回结果数组*/
  public function article_all(){
    $data = $this ->db->select('aid,title,time,cid,thumb')->get('article')->result_array();
    return $data;
  }

  /*根据偏移量查询记录,返回结果数组*/
  public function article_list_limit($perPage, $offset){
    $data = $this ->db->select('aid,title,time,cid,thumb,content')->limit($perPage, $offset)->get('article')->result_array();
    return $data;
  }

  /*查询单条记录的详细内容,返回结果对象*/
  public function article_one($aid){
    $data = $this->db->get_where('article',array('aid'=>$aid))->row();
    return $data;
  }

  /*插入新的记录,返回受影响行数*/
  public function insert($data){
    $this->db->insert('article', $data);
    return $this->db->affected_rows();
  }

  /*更新原有记录,返回受影响行数*/
  public function update($aid,$data){
    $this->db->update('article', $data,array('aid'=>$aid));
    return $this->db->affected_rows();
  }

  /*删除对应记录,返回受影响行数*/
  public function delete($aid)  {
      $this->db->delete('article',array('aid'=>$aid));
      return $this->db->affected_rows();
    }

}